Giovanni Zilli adds slope handling to subrip format.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 20 Jun 2015 13:34:46 +0000 (13:34 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 20 Jun 2015 13:34:46 +0000 (13:34 +0000)
gpsbabel/defs.h
gpsbabel/subrip.cc
gpsbabel/waypt.cc
gpsbabel/xmldoc/formats/options/subrip-format.xml

index 6a06920db6bef585c659029c02d0128889b359cc..9a8cf0391e1a4665101f9ee7a237ae7db18bd1bd 100644 (file)
@@ -867,6 +867,7 @@ double waypt_time(const Waypoint* wpt);
 double waypt_speed(const Waypoint* A, const Waypoint* B);
 double waypt_speed_ex(const Waypoint* A, const Waypoint* B);
 double waypt_vertical_speed(const Waypoint* A, const Waypoint* B);
+double waypt_gradient(const Waypoint* A, const Waypoint* B);
 double waypt_course(const Waypoint* A, const Waypoint* B);
 double waypt_distance(const Waypoint* A, const Waypoint* B);
 double waypt_distance_ex(const Waypoint* A, const Waypoint* B);
index 9490aadf48dfef31070818f451f323a67265d328..d4e23a6d45256030e36af1a431c4569aed36dfd8 100644 (file)
@@ -34,6 +34,7 @@ static int stnum;
 static gbfile* fout;
 static const Waypoint* prevwpp;
 static double vspeed;
+static double gradient;
 
 /* internal helper functions */
 
@@ -110,6 +111,9 @@ subrip_prevwp_pr(const Waypoint* waypointp)
       case 'v':
         gbfprintf(fout, "%2.2f", vspeed);
         break;
+      case 'g':
+          gbfprintf(fout, "%2.1f%%", gradient);
+          break;
       case 't':
         {
           QTime t = prevwpp->GetCreationTime().toUTC().time();
@@ -183,6 +187,7 @@ subrip_trkpt_pr(const Waypoint* waypointp)
   if (prevwpp) {
     subrip_prevwp_pr(waypointp);
     vspeed = waypt_vertical_speed(waypointp, prevwpp);
+    gradient = waypt_gradient(waypointp, prevwpp);
   }
   prevwpp = waypointp;
 }
@@ -201,6 +206,7 @@ subrip_wr_init(const char* fname)
 
   prevwpp = NULL;
   vspeed = 0;
+  gradient = 0;
 
   if ((opt_gpstime != NULL) && (opt_gpsdate != NULL)) {
     time(&gpstime_t);
index 15706c5a12adeed09222af3da0a8a4ef83224b47..93c60b4c81ae7af5ed1d7a0532961cb55e99d218 100644 (file)
@@ -564,6 +564,29 @@ waypt_vertical_speed(const Waypoint* A, const Waypoint* B)
   }
 }
 
+/*
+ * Returns "Road Gradient" between A and B as a percentage of slope.
+ * If there is no distance or either A or B have unknown altitude, return 0.
+ */
+double
+waypt_gradient(const Waypoint* A, const Waypoint* B)
+{
+  double dist, altitude, gradient;
+  dist = waypt_distance(A, B);
+  if (dist == 0) {
+    return 0;
+  }
+
+  altitude = A->altitude - B->altitude;
+  if (altitude == 0 || 
+      A->altitude == unknown _alt || B->altitude == unknown_alt) {
+    return 0;
+  }
+
+  gradient = (altitude / dist) * 100;
+  return (gradient);
+}
+
 /*
  * Calculates "Course True" from A to B
  */
index 1d017a6787d918e580a019572af128808b6c5dbf..c6f1054e54ae9d52d1086eb7af6ab34a02c6acce 100644 (file)
   <entry>%h</entry>
   <entry>heart rate</entry>
 </row>
+<row>
+  <entry>%g</entry>
+  <entry>road gradient</entry>
+</row>
 <row>
   <entry>\n</entry>
   <entry>newline</entry>